fix(cmd): fail fast when marking an unknown flag required#1771
Conversation
MarkFlagRequired errors only when the named flag does not exist, and every call site discarded that error, silently making the flag optional. Route all calls through a helper that panics on an unknown name. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds and tests a shared ChangesRequired flag validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Coverage Report for CI Build 29898091278Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.1%) to 46.233%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions315 previously-covered lines in 8 files lost coverage.
Coverage Stats
💛 - Coveralls |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Summary
MarkFlagRequiredreturns an error only when the named flag is not defined on the command. All 49 call sites in cmd/ discarded it, so a mistyped or renamed flag name silently made the flag optional.Changes
mustMarkRequiredincmd/flags.go: marks each named flag required and panics if the flag does not exist, naming the flag and the commandcmd.MarkFlagRequired(...)calls across 11 files withmustMarkRequired(cmd, ...)cmd/flags_test.gocovering both pathsTechnical Details
The helper runs during command construction, before flag parsing. A wrong flag name now crashes every CLI run and every
go test ./cmd/instead of shipping a command whose required flag is quietly optional. Current flag names are all valid: the existing cmd tests construct every command and none of the calls panic.Test Plan
go test ./cmd/passes